<!--
 * @Author: your name
 * @Date: 2021-05-26 22:44:35
 * @LastEditTime: 2021-06-15 15:57:03
 * @LastEditors: YaoXiaoTian
 * @Description: In User Settings Edit
 * @FilePath: \tourismpc\src\views\tourism\components\culturalAttractions\detail\detail.vue
-->
<template>
  <div>
    <div class="culturaldetail">
      <div class="tipsPrice">
        <div class="keyWord">
          <h3>{{ detailData.spotName }}</h3>
        </div>
        <div>
          <span class="set"></span>
          <span class="price">{{ detailData.spotPrice }}RMB</span>起
        </div>
      </div>
      <el-divider></el-divider>
      <div class="text">
        <div class="titleText">景点介绍</div>
        <br />
        <div style="text-indent: 2em">{{ detailData.spotIntro }}</div>
        <div class="spotImg">
          <img :src="detailData.titleImgUrl" alt />
        </div>
        <br />
        <div class="titleText">游客须知</div>
        <br />
        <div style="text-indent: 2em">{{ detailData.spotNotice }}</div>
      </div>
      <br />
      <div class="mapDiv">
        <span class="titleText">定位导航</span>
        <!-- <el-input class="searchInput" v-model="address" placeholder="请输入地址">
          <el-button @click="onSearch" slot="append" icon="el-icon-search"></el-button>
        </el-input> -->
        <div
          id="mapContainer"
          style="width: 1220px; height: 614px; margin-top: 20px"
        ></div>
      </div>

      <div
        class="nextPage"
        @click="getDetail(detailData.spotInfoListDto[0].spotId)"
      >
        下一页：
        <span v-if="detailData.spotInfoListDto">{{
          detailData.spotInfoListDto[0].spotName
        }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { get_data } from "../../../../../utils/utils";
export default {
  data() {
    return {
      geocoder: null,
      marker: null,
      api: this.$apiPath.getSpotInfo,
      address: "",
      detailData: {},
      coordinate: {
        longitude: 104.07,
        latitude: 30.67,
      },
    };
  },
  created() {
    this.getDetail();
  },
  watch: {
    $route(to, from) {
      //监听路由是否变化
      if (to.query.spotId != from.query.spotId && to.query.spotId != null) {
        //pid不为空才请求数据
        this.getDetail(); //调接口，请求数据
      }
    },
  },
  mounted() {},
  methods: {
    initMap() {
      //步骤：定义map变量 调用 qq.maps.Map() 构造函数   获取地图显示容器
      //设置地图中心点
      let that = this;
      var myLatlng = new qq.maps.LatLng(
        this.coordinate.latitude,
        this.coordinate.longitude
      );
      //定义工厂模式函数
      var myOptions = {
        zoom: 15, //设置地图缩放级别
        center: myLatlng, //设置中心点样式
        mapTypeId: qq.maps.MapTypeId.ROADMAP, //设置地图样式详情参见MapType
        zoomControl: false, //隐藏缩放控件
        panControl: false, //隐藏平移控件
      };
      //获取dom元素添加地图信息
      var map = new qq.maps.Map(
        document.getElementById("mapContainer"),
        myOptions
      );
      that.marker = new qq.maps.Marker({
        map,
        position: myLatlng,
      });
      this.geocoder = new qq.maps.Geocoder({
        complete(result) {
          map.setCenter(result.detail.location);
          if (that.marker) {
            that.marker.setMap(null);
          }
          that.marker = new qq.maps.Marker({
            map,
            position: result.detail.location,
          });
        },
      });
    },
    onSearch() {
      this.geocoder.getLocation(this.address);
    },
    getDetail(spotId) {
      let that = this;
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
      this.$http
        .fetch(
          `${this.api}?spotId=${spotId ? spotId : this.$route.query.spotId}`,
          {
            method: "get",
          }
        )
        .then((res) => {
          if (res.code === 200) {
            this.detailData = res.data;
            this.coordinate.latitude = res.data.latitude;
            this.coordinate.longitude = res.data.longitude;
            that.initMap();
          }
        })
        .catch((err) => {
          return Promise.reject(err);
        });
    },
    addCollect(spotId) {
      this.$http
        .fetch(`${this.$apiPath.addCollect}`, {
          method: "post",
          data: {
            sightId: spotId,
            userId: JSON.parse(get_data("userInfo")).id,
          },
        })
        .then((res) => {
          if (res.code === 200) {
            this.$message.success(res.msg);
          } else if (res.code === 400) {
            this.$message.success(res.msg);
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((err) => {
          return Promise.reject(err);
        });
    },
  },
};
</script>

<style lang="less">
.culturaldetail {
  width: 1220px;
  margin: 0 auto;
  .tipsPrice {
    overflow: hidden;
    color: #999999;
    div {
      &:nth-child(1) {
        float: left;
      }
      &:nth-child(2) {
        float: right;
        .set {
          display: inline-block;
          width: 1px;
          height: 40px;
          background: #999999;
          margin-right: 16px;
        }
      }
    }
    .price {
      font-size: 36px;
      color: #f44a22;
      margin-bottom: -4px;
    }
    .keyWord {
      height: 46px;
      line-height: 46px;
      color: #333333;
    }
  }
  .text {
    color: #666666;
    .spotImg {
      width: 700px;
      height: 450px;
      margin: 48px auto;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .mapDiv {
    position: relative;
    .searchInput {
      position: absolute;
      z-index: 999;
      top: 60px;
      left: 22px;
    }
  }
  .titleText {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #333333;
    line-height: 8px;
  }
  .el-input-group {
    width: 400px;
    .el-input-group__append {
      background-color: #cf975a;
      .el-icon-search {
        color: #fff;
      }
    }
  }
  .buyTicket {
    margin: 50px 0;
    .buyButton {
      cursor: pointer;
      width: 128px;
      height: 36px;
      background-color: #cf975a;
      border-radius: 18px;
      text-align: center;
      line-height: 36px;
      margin: 0 auto;
      color: #fff;
    }
  }
  .favoriteCollection {
    margin-top: 40px;
    .flexBox {
      margin: 0 auto;
      width: 220px;
      display: flex;
      justify-content: center;
      align-items: center;
      .boxItem {
        display: flex;
        align-items: center;
        width: 60px;
        color: #666666;
        cursor: pointer;
        img {
          margin-right: 3px;
        }
      }
    }
  }
  .nextPage {
    margin: 0 auto;
    color: #666666;
    text-align: center;
    margin-top: 39px;
    margin-bottom: 50px;
    cursor: pointer;
  }
}
</style>
